// GlutSample.cpp : Defines the entry point for the console application.
//

#include <stdafx.h>
#include <glut.h>

#include "InputSystem.h"
#include "RenderSystem.h"

static const int s_WindowWidth = 800;
static const int s_WindowHeight = 600;

static CInputSystem s_InputSystem;
static CRenderSystem s_RenderSystem;

static void HandleDisplay( )
{
	s_InputSystem.Update( );
	s_RenderSystem.Update( );

	glutSwapBuffers( );
}

static void HandleReshape( const int inWidth, const int inHeight )
{
	glViewport( 0, 0, inWidth, inHeight );
}

static void HandleIdle( )
{
	glutPostRedisplay( );
}

static void HandleKeyBoard( const unsigned char inKey, const int inPosX, const int inPosY )
{
	s_InputSystem.HandleKeyboard( inKey, inPosX, inPosY );
}

static void HandleSpecialKey( const int inKey, const int inPosX, const int inPosY )
{
	s_InputSystem.HandleSpecialKey( inKey, inPosX, inPosY );
}

static void HandleMouse( const int inButton, const int inState, const int inPosX, const int inPosY )
{
	s_InputSystem.HandleMouse( inButton, inState, inPosX, inPosY );
}

static void HandleMotion( const int inPosX, const int inPosY )
{
	s_InputSystem.HandleMotion( inPosX, inPosY );
}

int main( int argc, char** argv )
{
	glutInit( &argc, argv );
	glutInitWindowSize( s_WindowWidth, s_WindowHeight );
	glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
	
	int theWindowHandle = glutCreateWindow( "Default Application" );
	glutSetWindow( theWindowHandle );

	glutDisplayFunc( HandleDisplay );
	glutReshapeFunc( HandleReshape );
	glutIdleFunc( HandleIdle );
	glutKeyboardFunc( HandleKeyBoard );
	glutSpecialFunc( HandleSpecialKey );
	glutMouseFunc( HandleMouse );
	glutMotionFunc( HandleMotion );
	HandleMotion( 0, 0 );
	
	// Setup default render states
	glClearColor( 0.3f, 0.3f, 0.3f, 1.0 );
	glEnable( GL_DEPTH_TEST );
	glEnable( GL_COLOR_MATERIAL );

	glutMainLoop( );

	return 0;
}

